import XRequest from '@/library/XRequest'


const $request = new XRequest()
$request.config.baseUrl = "http://localhost:3000"
$request.config.isJson = true
$request.config.headers = {
    'content-type': 'application/json'
}
$request.interceptor.response.convert = (xhr) => {
    const contentType = xhr.getResponseHeader('content-type')
    if (contentType.includes('application/json')) {
        return JSON.parse(xhr.responseText)
    }
    return xhr.response
}
$request.interceptor.response.text = (res) =>{
    switch (res.code) {
        case 300:
        console.log(res.message);
            break;
        case 400:
        console.log('未登录');
            break;
    }
}
$request.interceptor.request = (init) => {
    let headers = init.headers ?? {}
    headers = {
        ...headers,
    }
    init.headers = headers;
    return init
}

export default $request